<?php
	/*
	* Nusaview Component for Joomla! 1.5.x
	* Version 1.0
	* Creation date: March 2009
	* Author: Angga Rajasa - Nur Aini Rakhmawati
	* Author email: rajasa.angga@gmail.com
	* License GNU/GPL
	*/

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();

jimport( 'joomla.application.component.view' );
class NvViewKota extends JView{

	function display($tpl = null){
	
		//----------------------  an instance of JApplication
		global $mainframe, $option;
		
		//----------------------   load data from kotas's model
		$pageNav =& $this->get( 'Pagination' );
		$kota	 =& $this->get('Data');
		
		//----------------------   if user request a kota's form then load this		
		if ($this->getLayout() == 'form') {	
		
			//----------------------   Setting up Toolbar for Kota's form
			$isNew = ($kota->id < 1);	
			$text = $isNew ? JText::_( 'New' ) : JText::_( 'Edit' );
			JToolBarHelper::save();
			if ($isNew)  {
				JToolBarHelper::cancel();
			} else {
				JToolBarHelper::cancel( 'cancel', 'Close' );
			}			
		
			//---------------------- load  an instance of JDatabase
			$db		=& JFactory::getDBO();
			//---------------------- make array for combobox
			$lists = array();
	
			//---------------------- load data if user request an edit form		
			$row =& JTable::getInstance('kota', 'Table');
			$cid = JRequest::getVar( 'cid', array(0), '', 'array' );
			$pid = JRequest::getVar( 'pid', array(0), '', 'array' );
			$row->load($pid[0],$cid[0]);

			// ---------------------------- get query propinsi all 
			$query = 'SELECT s.propinsi_id, s.nama_propinsi' .
					' FROM #__propinsi AS s' .
					' ORDER BY s.propinsi_id';
			$db->setQuery($query);
			
			/*
			 * if user request an edit's form then propinsi's combo will be disabled
			 */
			if ( $cid[0] != null ) 
				$disabled = 'disabled';
			else
				$disabled = '';
	
			$propinsi_ids[] = JHTML::_('select.option', '-1', '- '.JText::_('Pilih Propinsi').' -', 'propinsi_id', 'nama_propinsi');
			$propinsi_ids = array_merge($propinsi_ids, $db->loadObjectList());
			$lists['propinsi_id'] = JHTML::_('select.genericlist',  $propinsi_ids, 'propinsi_id', 'class="inputbox" size="1" '.$disabled, 'propinsi_id' , 'nama_propinsi', intval($row->propinsi_id));			
			//----------------------   send to views as an object
			$this->assignRef('kota',$kota);
			$this->assignRef('lists',	$lists);				
		}
		else {
			//----------------------   Assign top menu of nusaview's component			
			JSubMenuHelper::addEntry( '<span class="editlinktip hasTip" title="'.JText::_( 'Objek Pariwisata' ).'::'.JText::_('Data-Data Pariwisata').'">'.JText::_( 'Objek Pariwisata' ).'</span>', 'index.php?option=com_nv&controller=objek');
			JSubMenuHelper::addEntry( '<span class="editlinktip hasTip" title="'.JText::_( 'Master Propinsi' ).'::'.JText::_('Master Data Propinsi').'">'.JText::_( 'Master Propinsi' ).'</span>', 'index.php?option=com_nv&controller=propinsi');
			JSubMenuHelper::addEntry( '<span class="editlinktip hasTip" title="'.JText::_( 'Master Kota' ).'::'.JText::_('Master Data Kota').'">'.JText::_( 'Master Kota' ).'</span>', 'index.php?option=com_nv&controller=kota', true);
			//JSubMenuHelper::addEntry( '<span class="editlinktip hasTip" title="'.JText::_( 'Konfigurasi' ).'::'.JText::_('Setting up Form Input').'">'.JText::_( 'Konfigurasi' ).'</span>', 'index.php?option=com_nusaview&controller=konfigurasi');
		/*
			JSubMenuHelper::addEntry( '<span class="editlinktip hasTip" title="'.JText::_( 'Marker' ).'::'.JText::_('Marker GoogleMap').'">'.JText::_( 'Marker' ).'</span>', 'index.php?option=com_nusaview&controller=markers');
		*/			
			
			//----------------------   Setting up Toolbar
			JHTML::_('behavior.tooltip');
			JToolBarHelper::title(   JText::_( 'Master Kota Nusantara View' ), 'generic.png' );
			JToolBarHelper::deleteList();
			JToolBarHelper::editListX();
			JToolBarHelper::addNewX();

			//----------------------   send to views as an object
			$this->assignRef('items',$kota);			
			$this->assignRef('pageNav', $pageNav);			
		}
		//send to html
		parent::display($tpl);

	}// end of function
}// end of class

